package com.aboo.dao.impl;

import java.util.List;

import com.aboo.dao.BaseSqlMapDao;
import com.aboo.dao.MenuDao;
import com.aboo.po.MenuPO;
import com.aboo.po.Page;
import com.aboo.pub.constant.Constant;

public class MenuDaoImpl extends BaseSqlMapDao implements MenuDao {

	public Integer save(MenuPO po) throws Exception {
		return (Integer) getSmcTemplate().insert("Menu.insertMenu", po);
	}

	public void delete(Integer id) throws Exception {
		MenuPO tmp = new MenuPO();
		tmp.setId(id);
		tmp.setInUse(Constant.INUSE_NO);
		getSmcTemplate().update("Menu.updateMenu", tmp);
	}

	public MenuPO find(MenuPO po) throws Exception {
		return (MenuPO) getSmcTemplate().queryForObject("Menu.selectMenuList", po);
	}

	public Integer findCount(MenuPO po) throws Exception {
		return (Integer) getSmcTemplate().queryForObject("Menu.selectMenuCount", po);
	}

	public List<MenuPO> findList(MenuPO po, Page page)
			throws Exception {
		if (page != null) {
			po.setBeginIndex(page.getBeginRecordIndex());
			po.setEndIndex(page.getEndRecordIndex());
		}
		po.addSort("ID", Constant.SORT_ASC);
		return getSmcTemplate().queryForList("Menu.selectMenuList", po);
	}

	public void update(MenuPO po) throws Exception {
		getSmcTemplate().update("Menu.updateMenu", po);
	}

}
